define([
	'../libs/zepto',
	'../common/ajax',
	'../common/yingSoftPrg',
	'../common/yingSoftCookie',
	'../common/dialog',
	'../common/userAction',
	'../common/agentInfo'
], function() {
	this.init = function() {
		set();
	}

	function set() {
    function e() {
        G_Prg.$("back").onclick = function() {
        	
            window.location.href = "/knowledgeChapter?fromUrl=knowledgeList";
        },
        G_Prg.$("check").onclick = function() {
            return "null" === a ? void G_Prg.alert("暂无关联章节试题。") : void(window.location.href = "answerExam?fromUrl=knowledgeList&chapterID=" + o + "&chapterName=" + l)
        }
    }
    function t(e, t) {
        var i = G_Cookie.getUserID(),
        r = G_Cookie.getGuid(),
        o = "/api/knowledge/getKnowledge",
        l = {
            userID: i,
            guid: r,
            appID: t,
            materialCptID: e,
            materialID: G_Prg.getCookie("MATERIALID")
        };
        G_AjaxApi_Record.post(o, l, !1,
        function(e) {
            var t = JSON.parse(e);
            if (200 === t.status) {
                var o = t.data,
                l = o.knowledge;
                n(l)
            } else if (201 === t.status) G_Prg.alert("知识点信息为空。",
            function() {
                window.location.href = "knowledgeChapter"
            });
            else if (202 === t.status) {
                if (!i && !r) return void G_Prg.alert("请登录后查看更多内容。",
                function() {
                    window.location.href = "/knowledgeChapter"
                });
                $('#check').css('display','none');
                $('.back').css('display','none');
                G_Prg.confirm("请购买后查看更多内容。",
                function() {
                    window.location.href = "/recharge?fromUrl=knowledgeList"
                },function() {
                    window.location.href = "/knowledgeChapter";
                })
            } else 300 === t.status ? G_Prg.alert("程序运行错误，knowledgeList. getKnowledge,数据库获取数据异常。",
            function() {
                window.location.href = "/knowledgeChapter"
            }) : 400 === t.status ? G_Prg.alert("程序运行错误，knowledgeList. getKnowledge,参数错误。",
            function() {
                window.location.href = "/knowledgeChapter"
            }) : G_Prg.alert('抱歉，knowledgeList. getKnowledge，不能处理 status = "' + t.status + '"！',
            function() {
                window.location.href = "/knowledgeChapter"
            })
        })
    }
    function n(e) {
        G_Prg.$("knowledgeUl").innerHTML = "";
        for (var t = 0; t < e.length; t++) {
            var n = t + 1 + "、" + e[t].Summary,
            o = e[t].KnowledgeText;
            n = r(n),
            o = r(o);
            var l = document.createElement("li");
            l.id = t;
            var a = document.createElement("div"),
            g = document.createElement("span");
            a.innerHTML = n,
            g.innerHTML = o,
            g.style.display = "none",
            g.id = t + "_text",
            l.appendChild(a),
            l.appendChild(g),
            l.onclick = function() {
                i(this.id)
            },
            G_Prg.$("knowledgeUl").appendChild(l)
        }
    }
    function i(e) {
//      G_UserAction.addUserAction("knowledgeDetail");
        var t = e + "_text";
        if (G_Prg.$(t)) {
            var n = G_Prg.$(t);
            "block" === n.style.display ? n.style.display = "none": n.style.display = "block"
        }
    }
    function r(e) {
        function t(e) {
            var t = c + e.substr(1, e.length - 2);
            t = t.replace(/#/g, "%23");
            var n = location.pathname.split("/"),
            i = n[n.length - 1];
            return "doExam-index" === i || "testList" === i ? '<img style="max-width:100%;height:auto;vertical-align:middle;" onclick="G_ImageZoom(this);" src="' + t + '"/>': '<img style="max-width:100%;height:auto;" src="' + t + '"/>'
        }
        var n = [],
        i = 0,
        r = "";
        if (!e) return e;
        for (; e.length > i && e.indexOf("[", i) > -1;) {
            var o = e.indexOf("[", i);
            n.push(o),
            i = o + 1
        }
        if (0 === n.length) return e;
        for (var l = [], a = 0; a < n.length; a++) {
            var g = n[a],
            d = e.indexOf("]", g);
            if (d > -1 && (a !== n.length - 1 && n[a + 1] > d || a === n.length - 1 && n[a] < d)) {
                var s = e.substring(g + 1, d); (s.indexOf(".gif") >= 0 || s.indexOf(".GIF") >= 0 || s.indexOf(".jpg") >= 0 || s.indexOf(".JPG") >= 0 || s.indexOf(".png") >= 0 || s.indexOf(".PNG") >= 0) && l.push([g, d + 1])
            }
        }
        if (0 === l.length) return e;
        for (var h = G_Cookie.getAppEName(), c = "http://t.api.ksbao.com/tk_img/ImgDir_" + h + "/knowledge_img/", a = 0; a < l.length; a++) 0 === a ? (r = e.substring(0, l[a][0]), r += t(e.substring(l[a][0], l[a][1])), 1 === l.length && (r += e.substring(l[a][1], e.length))) : a === l.length - 1 ? (r += e.substring(l[a - 1][1], l[a][0]), r += t(e.substring(l[a][0], l[a][1])), r += e.substring(l[a][1], e.length)) : (r += e.substring(l[a - 1][1], l[a][0]), r += t(e.substring(l[a][0], l[a][1])));
        return r.replace(new RegExp("\r", "gm"), "<br/>").replace(new RegExp("\n", "gm"), "")
    }
    var o = G_Prg.getQueryString("chapterID"),
    l = G_Prg.getQueryString("chapterName", !0),
    a = G_Prg.getCookie("KNOWLESGECPTID");
    if (!o) return void G_Prg.alert("章节id为空，不能显示知识点列表。",
    function() {
        window.location.href = "knowledgeChapter"
    });
    var g = G_Cookie.getAppID();
    return g ? (e(), void t(o, g)) : void G_Prg.alert("科目id为空，不能显示知识点列表。",
    function() {
        window.location.href = "knowledgeChapter"
    })
}
	init();
})